<?php
/**
 * Created by PhpStorm.
 * User: dust2
 * Date: 15-1-2
 * Time: 下午2:41
 */

/**
 * 订单表播种
 * Class OrderTableSeeder
 */
class OrderTableSeeder extends Seeder
{
    public function run()
    {
        DB::table('orders')->delete();

        DB::table('orders')->insert([
            'user_id' => 1,
            'orderNum' => $this->getOrderNum(),
            'status_id' => 1,
            'total' => 50.03,
            'receiver' => 'admin',
            'phone' => '12345678909',
            'postcode' => '234562',
            'deliverAddress' => '广东-广州-天河　中山大道西55号西三117',
            'created_at' => $this->getTime(),
            'updated_at' => $this->getTime()
        ]);

        DB::table('orders')->insert([
            'user_id' => 2,
            'orderNum' => $this->getOrderNum(),
            'status_id' => 2,
            'total' => 230,
            'receiver' => 'rocky',
            'phone' => '12345678902',
            'postcode' => '234562',
            'deliverAddress' => '广东-广州-天河　中山大道西55号西三207',
            'created_at' => $this->getTime(),
            'updated_at' => $this->getTime()
        ]);
    }

    /**
     * 获取订单号
     * @return string
     */
    private function getOrderNum()
    {
        $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
        return $yCode[(intval(date('Y')) - 1971)%10].strtoupper(dechex(date('m'))).date('d').substr(time(), -5).substr(microtime(), 2, 5).sprintf('%02d', rand(0, 99));
    }

    /**
     * 获取固定格式时间
     * @return bool|string
     */
    private function getTime()
    {
        return date('Y-m-d h:m:s');
    }
}